## Run on R Version 3.3.0 for windows

library(ggplot2)
library(foreign)
setwd("") # Set your working directory


### 2008/2012

d <- read.table("cces_stacked.txt",header=T)

d$pe <- d$c1
d$se <- d$c2
d$lb <- d$pe- 1.64*d$se
d$ub <- d$pe+ 1.64*d$se


d$group <- factor(d$c4,levels=c(6,5,4,3,2,1),
                  labels=c("Party ID (2008)","Ideology (2008)","Vote Choice (2008)","Party ID (2012)","Ideology (2012)","Vote Choice (2012)")[6:1])

d$Race <- factor(d$c3,levels=c(1,2,3,4),labels=c("White","Black","Hispanic","Asian")[1:4] )

f5b = ggplot() + geom_pointrange(data=d, mapping=aes(x=group, y=pe, ymin=lb, ymax=ub, fill=Race,shape=Race), position = position_dodge(width=.5))
#f5b = f5b + scale_y_continuous(name="Extremity") 
f5b = f5b + scale_x_discrete(name="")
f5b = f5b + scale_shape_manual(values=c(21,24,22,23))  # as before
f5b = f5b + scale_fill_manual(values=c("black","gray25","gray75","white"))
#f5b = f5b + opts(title="       Figure 5b: Mean Issue Extremity by Condition", plot.title=theme_text(size=20))  
f5b <- f5b + ylab("                    Liberalism") + xlab("Liberalism")
f5b <- f5b + coord_flip()
print(f5b)



